﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BKO.DataAccesss;
using BKO.DataAccesss.Repositories;
using BKO.Domain.Model;
using BKO.Domain.Services;

namespace BKO.Services
{
	public class CabinetService : BaseService<ICabinet>, ICabinetService
	{
		public CabinetService(string connectionString)
			: base(new BaseRepository<ICabinet, CabinetEntity>(BKODataContextSingletone.GetInstance(connectionString)))
		{
		}

		public List<ICabinet> GetAllByFilialAndOtdel(int filialId, int otdelId, bool visible)
		{
			IQueryable<ICabinet> query = Repository.GetAll()
				.Where(c => c.FilialId == filialId && c.OtdelId == otdelId);

			if (!visible)
			{
				query = query.Where(c => c.ARHIV == 0);
			}
			query = query
				.OrderBy(c => ((CabinetEntity)c).FilialEntity.Name)
				.OrderBy(c => ((CabinetEntity)c).OtdelEntity.Name)
				.OrderBy(c => c.Name);

			return query.ToList();
		}
	}
}
